// pages/subrogation/debtInfo/info/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        parameter: {
            'navbar': '1',
            'return': '1',
            'title': '垫付详情',
            'color': true,
            'class': false
        },
        dialog: false,
        call: false,
        pageH: app.globalData.pageHeight,
        pageNum: 1,
        picUrl: app.imagesURL,
        salesmanId: wx.getStorageSync('userInfo').id
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options)
        this.setData({
            dealerIdId: options.id
        })
        this.orderInfo()
        this.orderList()
        this.getHeight1()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow(options) {

    },

    //  获取高度适配列表高度
    getHeight1() {
        var that = this;
        wx.createSelectorQuery().selectAll('.navbar').boundingClientRect().exec(function (res) {
            console.log(res)
            that.setData({
                listHeight: res[0][0].height
            })
        })
    },

    /* 垫付详情 */
    orderInfo(e) {
        var that = this;
        // /bdb/WorkerBee/paymentDetailsInfo
        app.baseGet(app.U({
            m: 'bdservice',
            c: 'bdb/WorkerBee',
            a: 'paymentDetailsInfo',
            q: {
                salesmanId: that.data.salesmanId,
                dealerId: that.data.dealerIdId
            }
        }), (res) => {}, res => {
            that.setData({
                orderInfo: res.data
            })
        })
    },


    /* 欠款内容 */
    orderList(e) {
        var that = this,
            pageNum = 1,
            list = [];
        // /bdb/WorkerBee/paymentDetailsList
        app.baseGet(app.U({
            m: 'bdservice',
            c: 'bdb/WorkerBee',
            a: 'paymentDetailsList',
            q: {
                salesmanId: that.data.salesmanId,
                pageNum: that.data.pageNum,
                pageSize: 10,
                dealerId: that.data.dealerIdId
            }
        }), (res) => {}, res => {
            console.log(res)
            pageNum = res.data.pageNum;
            if (pageNum == 1) {
                list = res.data.list;
            } else {
                list = app.SplitArray(res.data.list ? res.data.list : [], that.data.orderList) //分页合并数组
            }
            that.setData({
                orderList: list
            })
        })
    },

    /* 厂家结算 */
    settlement(e) {
        var that = this;
        // /bdb/WorkerBee/grtOrder
        app.baseGet(app.U({
            m: 'bdservice',
            c: 'bdb/WorkerBee',
            a: 'grtOrder',
            q: {
                retailOrderId: e.currentTarget.dataset.id
            }
        }), res => {}, (res) => {
            console.log(res)
            that.setData({
                dialogList: res.data,
                dialog: true
            })
        })
    },

    // 滚动到底部加载更多
    lower() {
        var pageNum = Number(this.data.pageNum) + 1;
        this.setData({
            pageNum: pageNum
        })
        this.orderInfo()
    },

    call(e) {
        console.log(e)
        var number = JSON.stringify(e.currentTarget.dataset.num)
        wx.makePhoneCall({
            phoneNumber: number
        })
    },

    closeOrder() {
        this.setData({
            dialog: false
        })
    },

    openPhone() {
        this.setData({
            call: true
        })
    },

    closePhone() {
        this.setData({
            call: false
        })
    }
})